package com.chaodriod.common.glide;


import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;

import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.ViewTarget;
import com.bumptech.glide.request.transition.Transition;

/**
 * Created by CHEN on 2018/4/13.
 */

public class GlideUtils
{

    private static RequestOptions mOptions = null;


    public static RequestOptions getGlideOptions(){
        if (mOptions == null) {
            mOptions = new RequestOptions()
                    .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
                    .skipMemoryCache(true)
                    .dontAnimate()
                    .fitCenter();
        }
        return mOptions;
    }

    public static class ViewBackgroundTarget extends ViewTarget<View,Drawable> {

        public ViewBackgroundTarget(@NonNull View view) {
            super(view);
        }

        public ViewBackgroundTarget(@NonNull View view, boolean waitForLayout) {
            super(view, waitForLayout);
        }

        @Override
        public void onResourceReady(@NonNull Drawable drawable, @Nullable Transition<? super Drawable> transition) {
            view.setBackground(drawable);
        }
    }
}
